<template>
  <!-- 搜索栏部分 -->
  <el-card class="search-card">
    <el-form :model="searchForm" label-width="80px" inline>
      <el-form-item label="姓名">
        <el-input v-model="searchForm.fullName" placeholder="姓名" clearable />
      </el-form-item>
      <el-form-item label="岗位">
        <el-input v-model="searchForm.remark" placeholder="岗位" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handlerSearch">搜索</el-button>
        <el-button @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 列表 -->
  <el-card class="table-card">
    <el-radio-group v-model="selectedUserId" style="width: 100%">
      <el-table
          :data="userList"
          border
          stripe
      >
        <el-table-column>
          <template #default="scope">
            <el-radio :value="scope.row.id"/>
          </template>
        </el-table-column>
        <el-table-column prop="username" label="昵称" />
        <el-table-column prop="fullName" label="姓名" />
        <el-table-column prop="remark" label="岗位" />
        <el-table-column prop="phone" label="联系电话" />
      </el-table>
    </el-radio-group>
  </el-card>
  <el-row style="margin: 40px">
    <el-button @click="doSelectUser">确定</el-button>
  </el-row>
</template>

<script setup>
//导入

//----------属性申明 ⬇
import {ref,onMounted} from "vue";
import {getUserList} from "@/api/user.js"
//查询表单
const searchForm = ref({
  username:"",
  fullName:"",
  remark:"",
  phone:""
})
//数据展示列表
const userList = ref([])
//返回数据
const selectedUserId = ref(-1);
//申明返回事件
const emit = defineEmits(["selectUser"]);
//----------属性申明 ⬆
//-----------函数申明 ⬇
//搜索列表
const handlerSearch = ()=>{
  let params = {}
  params = searchForm.value;
  params.pageNum = 1;
  params.size = 1000;
  getUserList(params).then(res=>{
    userList.value = res.data;
  })
}
//重置查询列表
const resetSearch = ()=>{
  searchForm.value = {
    username:"",
    fullName:"",
    remark:"",
    phone:""
  }
}
const doSelectUser = ()=>{
  emit("selectUser",selectedUserId.value)
}
//加载数据
onMounted( ()=>{
  resetSearch()
  handlerSearch();
})
//------------函数申明 ⬆

</script>

<style scoped>

</style>